import re

import allure

from pages.base_page import BasePage
from utils.test_data_utils import TestDataUtils


class InsurancePage(BasePage):
    @property
    def name_input(self):
        return self.page.get_by_role("textbox", name="姓名")
    @property
    def consort_name_input(self):
        return self.page.locator("input[name=\"mateName\"]")
    @property
    def cert_no_input(self):
        return self.page.get_by_role("textbox", name="身份证号")
    @property
    def consort_cert_no_input(self):
        return self.page.locator("input[name=\"mateCert\"]")
    @property
    @allure.step("勾选自动升级")
    def check_automatic_upgrade(self):
        return self.page.locator(".btn-box > .checkboxGroup > .headerCheckbox > span > .imgNoChecked")

    @property
    @allure.step("点击投保")
    def submit_button(self):
        if "version=v8_2" in self.page.url:
            return self.page.locator('img[src="//cdn.aibangbaoxian.net/netflow/magicCube/zxhm/img/v6/ljtb-btn.png"]')
        else:
            return self.page.locator('div.ljtb-btn')

    @allure.step("填写三要素")
    def fill_insurance_form(self,data):
        self.name_input.click()
        self.name_input.fill(data["name"])
        self.cert_no_input.fill(data["certNo"])
        return data

    @allure.step("填写配偶三要素")
    def fill_consort_insurance_form(self,data):
        self.page.locator("div").filter(has_text=re.compile(r"^配偶$")).get_by_role("radio").check()
        self.consort_name_input.click()
        self.consort_name_input.fill(data["name"])
        self.consort_cert_no_input.click()
        self.consort_cert_no_input.fill(data["certNo"])
        return data